package configuration;

import org.yaml.snakeyaml.Yaml;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Arrays;

public class SQLServerConfig {
    private String servername;
    private String portnumber;
    private String databasename;
    private String username;
    private String password;
    private String tablename;
    private String timestamp_col_name;
    private String[] field_col_names;
    private String[] id_field_col_names;
    private int inc_read_wait_mseconds;

    public String getServername() {
        return servername;
    }

    public void setServername(String servername) {
        this.servername = servername;
    }

    public String getPortnumber() {
        return portnumber;
    }

    public void setPortnumber(String portnumber) {
        this.portnumber = portnumber;
    }

    public String getDatabasename() {
        return databasename;
    }

    public void setDatabasename(String databasename) {
        this.databasename = databasename;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getTablename() {
        return tablename;
    }

    public void setTablename(String tablename) {
        this.tablename = tablename;
    }

    public String getTimestamp_col_name() {
        return timestamp_col_name;
    }

    public void setTimestamp_col_name(String timestamp_col_name) {
        this.timestamp_col_name = timestamp_col_name;
    }

    public int getInc_read_wait_mseconds() {
        return inc_read_wait_mseconds;
    }

    public void setInc_read_wait_mseconds(int inc_read_wait_mseconds) {
        this.inc_read_wait_mseconds = inc_read_wait_mseconds;
    }

    public String[] getField_col_names() {
        return field_col_names;
    }

    public void setField_col_names(String[] field_col_names) {
        this.field_col_names = field_col_names;
    }

    public String[] getId_field_col_names() {
        return id_field_col_names;
    }

    public void setId_field_col_names(String[] id_field_col_names) {
        this.id_field_col_names = id_field_col_names;
    }

    public static SQLServerConfig initFromFile(String filepath) throws FileNotFoundException {
        Yaml yaml = new Yaml();
        SQLServerConfig config = yaml.loadAs(new FileInputStream(new File(filepath)),
                SQLServerConfig.class);
        return config;
    }

    @Override
    public String toString() {
        return "SQLServerConfig {" +
                "\nserverName = " + servername +
                "\nportNumber = " + portnumber +
                "\ndatabaseName = " + databasename +
                "\nusername = " + username +
                "\npassword = " + password +
                "\ntablename = " + tablename +
                "\ntimestamp_col_name = " + timestamp_col_name +
                "\nfield_col_names = " + Arrays.asList(field_col_names) +
                "\nid_field_col_names = " + Arrays.asList(id_field_col_names) +
                "\ninc_read_wait_mseconds = " + inc_read_wait_mseconds +
                "\n}";
    }
}
